package solver


func verifyNaked(house *House, cellNums []int) (naked bool, values []int) {
	cands := [9]bool{}
	for _, cellNum := range cellNums {
		for i, candidate := range house.cells[cellNum].candidates {
			cands[i] = cands[i] || candidate
		}
	}

	valueCount := 0
	for _, cand := range cands {
		if cand {
			valueCount++
		}
	}
	naked = valueCount == len(cellNums)

	if !naked {
		return
	}
	for i, cand := range cands {
		if cand {
			values = append(values, i+1)
		}
	}
	return
}



func (g *Grid) nakedHouse(house *House, nakedCount int) (used bool) {
	cellNums := cellNumsForNaked(house, nakedCount)
	subsets := combine(cellNums, nakedCount)
	for _, subset := range subsets {
		naked, values := verifyNaked(house, subset[:])
		if !naked {
			continue
		}
		if clearupNakedHouse(house, subset, values) {
			used = true
		}
	}

	return
}


func (g *Grid) NakedPairHouse(house *House) (used bool) {
	return g.nakedHouse(house, 2)
}

func (g *Grid) NakedPair() (used bool) {
	return g.doStrategy(g.NakedPairHouse)
}

func (g *Grid) NakedTripleHouse(house *House) (used bool) {
	return g.nakedHouse(house, 3)
}

func (g *Grid) NakedTriple() (used bool) {
	return g.doStrategy(g.NakedTripleHouse)
}

func (g *Grid) NakedQuadrupleHouse(house *House) (used bool) {
	return g.nakedHouse(house, 4)
}

func (g *Grid) NakedQuadruple() (used bool) {
	return g.doStrategy(g.NakedQuadrupleHouse)
}

